package enums;

import java.util.StringJoiner;

/**
 * 枚举
 *
 * @author <a href="mailto:sjj@jianzhimao.com">mojo</a>
 * copyright (C), 2013-2022, 广州九尾信息科技有限公司
 * @date 2022/2/12 9:53
 */
public enum MyEnum {
    /**
     * 春天
     */
    SPRING(1, "春天"),
    /**
     * 夏天
     */
    SUMMER(2, "夏天"),
    /**
     * 秋天
     */
    AUTUMN(3, "秋天"),
    /**
     * 冬天
     */
    WINTER(4, "冬天");
    private final Integer num;
    private final String des;

    MyEnum(Integer num, String des) {
        this.num = num;
        this.des = des;
    }

    public Integer getNum() {
        return num;
    }

    public String getDes() {
        return des;
    }

    @Override
    public String toString() {
        return new StringJoiner(", ", MyEnum.class.getSimpleName() + "[", "]")
                .add("num=" + num)
                .add("des='" + des + "'")
                .toString();
    }

    public static MyEnum get(int num) {
        MyEnum[] values = MyEnum.values();
        for (MyEnum value : values) {
            if (value.num == num) {
                return value;
            }
        }
        return null;
    }

    public static void main(String[] args) {
        MyEnum myEnum = MyEnum.valueOf("SPRING");
        System.out.println(myEnum);
        MyEnum summer = Enum.valueOf(MyEnum.class, "summer".toUpperCase());
        System.out.println(summer);
        MyEnum myEnum1 = get(1);
        System.out.println(myEnum1);
        for (EnumInInterfaceDemo.Plant.Fruit f : EnumInInterfaceDemo.Plant.Fruit.values()) {
            System.out.println(f.getDescription());
        }
        System.out.println("===========================");
        System.out.println(PayrollDay.SUNDAY.pay(9, 400));
    }
}
